﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YmtAuth.Common._Extend
{
    public static class Enum_Extend
    {
        public static string GetDescription(this Enum v, string defDesc = null)
        {
            var name = Enum.GetName(v.GetType(), v);
            var fieldInfo = v.GetType().GetField(name);
            var desc = Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute), false) as DescriptionAttribute;
            
            if (desc == null) return defDesc;
            return desc.Description;

        }
    }
}
